package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.DeleteSellerPorductTagsBean;
import com.ymatou.iapi.productmanager.service.DeleteSellerPorductTagsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.utils.TestDataManager;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.List;
import java.util.Map;
/**
*删除营销标签
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteSellerPorductTags{
	private static DeleteSellerPorductTagsBean deletesellerporducttagsBean;
	private static DeleteSellerPorductTagsCall deletesellerporducttagsCall;
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除营销标签");
	}

	@Before
	public void caseUp() {
		deletesellerporducttagsBean=new DeleteSellerPorductTagsBean();
		deletesellerporducttagsCall=new DeleteSellerPorductTagsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletesellerporducttagsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteSellerPorductTags_001() {
		Logger.start(true,"删除营销标签成功");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			deletesellerporducttagsBean.setSellerId(sellerId);
			deletesellerporducttagsBean.setTagId(tagId);
			deletesellerporducttagsCall.setData(deletesellerporducttagsBean);
			deletesellerporducttagsCall.callService();			
			Logger.verifyEquals("200", deletesellerporducttagsCall.getString("Code"), "验证code");
			List<Map> list = intergratedProductMapper.selectYmtSellerProductTagById(tagId);
			Map m = list.get(0);
			Logger.debug(m);
			Logger.verifyEquals(-1, m.get("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteSellerPorductTags_002() {
		Logger.start(true,"不输入sellerid失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
//			deletesellerporducttagsBean.setSellerId(sellerId);
			deletesellerporducttagsBean.setTagId(tagId);
			deletesellerporducttagsCall.setData(deletesellerporducttagsBean);
			deletesellerporducttagsCall.callService();			
			Logger.verifyEquals("400", deletesellerporducttagsCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteSellerPorductTags_003() {
		Logger.start(true,"不输入tags失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			deletesellerporducttagsBean.setSellerId(sellerId);
//			deletesellerporducttagsBean.setTagId(tagId);
			deletesellerporducttagsCall.setData(deletesellerporducttagsBean);
			deletesellerporducttagsCall.callService();			
			Logger.verifyEquals("400", deletesellerporducttagsCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteSellerPorductTags_004() {
		Logger.start(true,"tagid和sellerid不一致修改失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			deletesellerporducttagsBean.setSellerId(sellerId+1);
			deletesellerporducttagsBean.setTagId(tagId);
			deletesellerporducttagsCall.setData(deletesellerporducttagsBean);
			deletesellerporducttagsCall.callService();			
			Logger.verifyEquals("201", deletesellerporducttagsCall.getString("Code"), "验证code");
			List<Map> list = intergratedProductMapper.selectYmtSellerProductTagById(tagId);
			Map m = list.get(0);
			Logger.debug(m);
			Logger.verifyEquals(0, m.get("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}